using System.Collections.Generic;
using System.Linq;

namespace BSpec.Specification
{
    public abstract class SpecificationElement
    {
        protected SpecificationElement(string name)
        {
            Name = name;
        }

        public string Name { get; private set; }
    }

    public static class SpecificationElementExtensions
    {
        public static bool HasElement<T>(this IEnumerable<T> elements, T element)
            where T : SpecificationElement
        {
            return elements.Any(e => e.Name == element.Name);
        }

        public static T GetElement<T>(this IEnumerable<T> elements, T element)
            where T : SpecificationElement
        {
            return elements.Single(e => e.Name == element.Name);
        }
    }
}